import { formatDate2 } from '@/utils/index'

export function exportFile(content, filename) {
  if (content && filename) {
    const blob = new Blob([content])
    const nowDate = new Date()

    const fileName = filename + formatDate2(nowDate, 'YYYYMMDDHHmmss') + '.xlsx'
    if ('download' in document.createElement('a')) {
      // 非IE下载
      const elink = document.createElement('a')
      elink.download = fileName
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(blob)
      document.body.appendChild(elink)
      elink.click()
      URL.revokeObjectURL(elink.href) // 释放URL 对象
      document.body.removeChild(elink)
    } else {
      // IE10+下载
      navigator.msSaveBlob(blob, fileName)
    }
  }
}
